<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <!--如果是IE 就以标准渲染-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

    <!-- 视窗——————响应式布局 -->
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" />

    <!--当前页面的三要素-->
    <title>运维系统</title>
    <meta name="description" content="聚能优电" />
    <meta http-equiv="keywords" content="聚能优电" />
    <script type="text/javascript" src="../../js/verify.js"></script>
    <script type="text/javascript" src="../../js/common/commonfuntion.js"></script>
    <!-- css -->
    <link rel="stylesheet" type="text/css" href="../../css/uploadImg.css" />
    <link rel="stylesheet" type="text/css" href="../../css/orderdetail.css" />
    <link rel="stylesheet" type="text/css" href="../../layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="../../css/mobiscroll.custom.min.css" />
    <link rel="stylesheet" href="https://at.alicdn.com/t/font_1805932_ysrcp4y0uy9.css">

    <style>
        html,body{
            height:100%;
        }

        .orderdetail_screen .tit_con .con_position .bottompart li{
            height:0.6rem;
        }
        .orderdetail_screen .tit_con .con_position .bottompart li .lileft{
            font-family: MicrosoftYaHei;
            font-size: 14px;
            color: #7F94B2;
            letter-spacing: 0.88px;
        }
        .orderdetail_screen .tit_con .con_position .bottompart li .liright{
            font-family: MicrosoftYaHei;
            font-size: 14px;
            color: #C3D4EA;
            letter-spacing: 0.88px;
        }
        .statewrap{
            margin-top:20px;
        }
        .statewrap .showstate{
            height:30px;
            line-height:30px;
            padding:0 20px;
            display:inline-block;
            border: 1px solid rgba(1,103,255,0.3);
            border-radius: 31px;
            font-family: SourceHanSansCN-Regular;
            font-size: 14px;
            color: #0167FF;
            letter-spacing: 1.75px;
        }

        /* 展示问题照片 */
        #showimg img{
            width: 80px;
            height: 80px;
            margin: 7px;
        }

        #showfile span{
            display: inline-block;
            padding: 0.1rem 0.2rem;
            font-family: MicrosoftYaHei;
            font-size: 0.28rem;
            color: #0167FF;
            letter-spacing: 0.88px;
            background: rgba(35, 62, 106,0.44);
            border-radius: 2px;
            margin-bottom: 0.2rem;
            margin-right: 0.2rem;
        }

				#ender p{
					font-size:12px;
				}
				#ender textarea{
					width: 94%;
    height: 1.5rem;
    padding: 0.1rem 2%;
    background: #001635;
    border: 1px solid #1B3150;
    color: #7F94B2;
				}

       


    </style>
</head>

<body>
    <div id="container" class="orderdetail">
        <div class="orderdetail_01">
            <!--主屏内容-->
            <div class="orderdetail_screen">
                <div class="m_title">
                    <a href="JavaScript:history.go(-1);" class="back">
                        <img src="../../images/back.svg" alt="">
                    </a>
                    <span class="tit" id="showname"></span>
                </div>

                <div class="tit_con">
                    <img src="../../images/orderbg.svg" alt="">
                    <div class="con_position">
                        <div class="toppart">
                            <div class="pleft floatpart" id="ordername">
                            </div>
                            <div class="pright floatpart" style="color:#34EE83;font-weight:bold;">
                                审核中
                            </div>
                        </div>
                        <ul class="bottompart">
                            <li>
                                <span class="lileft">填报人：</span><span class="liright" id="tbr"></span>
                            </li>
                            
                            <li>
                                <span class="lileft">审核人：</span><span class="liright" id="zxr"></span>
                            </li>
                            <li>
                                <span class="lileft">联系方式：</span><span class="liright" id="tel"></span>
                            </li>
                            <li>
                                <span class="lileft">创建时间：</span><span class="liright" id="createtime">2019-10-11 16:51:00</span>
                            </li>
                        </ul>
                    </div>

                </div>
                
                <!-- 问题描述 -->
                <div class="gj_tit title">问题描述</div>
                <div class="cljg hdnr_con" style="width:98%;margin-top:20px;color: #7F94B2;border:1px solid rgb(27, 49, 80);padding:5px 0;text-indent:5px;" id="questioncon">
                </div>

                <!-- 紧急程度 -->
                <div class="statewrap">
                    <span class="showstate" id="showstate"></span>
                </div>

                <!-- 问题照片 -->
                <div id="showimg_wrap">
                    <div class="gj_tit title">问题照片</div>
                    <div id="showimg" style="margin-top:10px;"></div>
                </div>

                <!-- 附件 -->
                <div id="showfile_wrap">
                    <div class="gj_tit title">附件</div>
                    <div id="showfile" style="margin-top:10px;">
                    </div>
                </div>

                
                <div id="fujian_wrap"></div>

              <div id="shoueditor">
								<div class="hdnr_tit title">审核处理</div>
								<div class="orderdeal">
										<input type="radio" name="deal" id="topass" value="0" /><label for="topass">审核通过</label>
										<input type="radio" name="deal" id="toback" value="1" /><label for="toback">审核驳回</label>
								</div>
								<!-- <div id="dealer" style="display:none;">
										<select name="" id="selectclr"></select>
								</div> -->
								<div id="ender" style="display:none;color:#7F94B2;">
								    <div>
												<p>驳回处理人:</span>
												<select name="" id="selectclr"></select>
										</div>
										<div>
												<p>驳回原因:</span>
												<textarea name="" id="selectend"></textarea>
										</div>
								</div>

								<div class="wrap_btn">
										<div class="sub_btn" style="margin-top:1rem;" id="sub_btn">提 交</div>
								</div>
						  </div>


            </div>
        </div>
    </div>


    <script>
        (function (win, doc) {
            var docEl = doc.documentElement || document.body; //获取HTML标签

            var container = doc.getElementById("container"); //container元素
            //判断是移动端设备还是PC,移动 就采用'orientationchange',横竖屏事件，PC端就采用onresize，窗口改变时间
            var resize =
                "onorientationchange" in win ? "orientationchange" : "resize";

            function rem() {
                docEl.style.fontSize = 100 * (container.clientWidth / 750) + "px";
            }

            //监听'DOMContent事件:DOM加载完成执行,如果DOMContent事件，那么执行rem函数
            doc.addEventListener("DOMContentLoaded", rem, false);

            //win下监听resize事件,如果resize事件，那么执行rem函数
            win.addEventListener(resize, rem, false);
        })(window, document);
    </script>
    <!-- js -->
    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/mobiscroll.custom.min.js"></script>
    <script type="text/javascript" src="../../layui/layui.js"></script>
    <script type="text/javascript" src="../../js/zooming.js"></script>
    <script>
        $(document).ready(function () {
            

            const getinfo = async () => {

                var projectid = GetQueryString('projectid');
                var orderID = GetQueryString('orderID');
                var projectNameCN = GetQueryString('projectname');
                var orderName = GetQueryString('orderName');

                $("#showname").html();
                $("#showname").html(projectNameCN);

                $("#ordername").html();
                $("#ordername").html(orderName);


                var stepnum;
                var resresult;
                var ordercontant;
                var dealcreattime;
                var orderzxr;
                // 获取填报人信息
                $.ajax({
                    type: "GET",
                    dataType: "json",
                    url: "http://112.74.169.99:21021/api/services/app/DevOpsService/GetAfterSaleOrder?id=" + orderID,
                    beforeSend: function (xhr) {
                        xhr.setRequestHeader("Accept",
                            "application/json, text/javascript, */*; q=0.01"
                        );
                        xhr.setRequestHeader("Authorization", accessToken);
                        xhr.setRequestHeader('.AspNetCore.Culture',
                            'zh-Hans');
                    },
                    success: function (res) {
                        console.log(res);
                        if(res.success){

                            stepnum = Number(res.result.stepnum) + 1;
                            resresult = res.result;
                            // 填报人
                            $("#tbr").html( res.result.creatername );
                            // 执行人
                            orderzxr = res.result.executorname;
                            $("#zxr").html( orderzxr );

							if( orderzxr != window.localStorage.getItem("name")){
                                $("#shoueditor").css('display','none');
                            }

                            // 联系方式
                            $("#tel").html(res.result.telePhone);

                            // 创建时间
                            var thecreattime = res.result.creattime;
                            dealcreattime = thecreattime.substring(0,10) + " " + thecreattime.substring(11,19);
                            $("#createtime").html(dealcreattime);

                            // 问题描述
                            $("#questioncon").html(res.result.problemDescription);

                            // 紧急程度
                            var degreeOfUrgency;
                            if(res.result.degreeOfUrgency == '1'){
                                degreeOfUrgency = '非常紧急';
                            }else if(res.result.degreeOfUrgency == '2'){
                                degreeOfUrgency = '紧急';
                            }else if(res.result.degreeOfUrgency == '3'){
                                degreeOfUrgency = '不紧急';
                            }
                            $("#showstate").html('');
                            $("#showstate").html(degreeOfUrgency);


                            // json格式内容
                            ordercontant = JSON.parse( res.result.ordercontant );
                            console.log(ordercontant);

                            window.localStorage.setItem('ordercontant',res.result.ordercontant);
                            
                            // 问题照片遍历
                            if(ordercontant["contant00"].uploadimg.length>0){
                                $("#showimg").html( imgeach(ordercontant["contant00"].uploadimg) );
                                
                            }else{
                                $("#showimg_wrap").css('display','none');
                            }

                            // 附件遍历
                            if(ordercontant["contant00"].uploadfile.length>0){
                                $("#showfile").html( eachfile(ordercontant["contant00"].uploadfile) );

                            }else{
                                $("#showfile_wrap").css('display','none');
                            }

                            if(stepnum > 1){
                                $("#fujian_wrap").append( eachhuidan(stepnum) );
                            }

                        }

                    },
                    error: function (err) {
                        console.log("请求失败");
                    }
                });



                // 图片
                function imgeach(uploadimg){
                    var str = '';
                    for(var i=0;i<uploadimg.length;i++){
                        str += `<img src="http://` + uploadimg[i] + `" alt="" data-action="zoom">`;
                    }
                    return str;
                }

                // 附件
                function eachfile(uplodfile){
                    var str = '';
                    for(var k=0;k<uplodfile.length;k++){
                        str += `<span onclick="window.location.href='http://112.74.169.99:21021/Temp/Upload/` + uplodfile[k][0] + `'">` + uplodfile[k][0] + `</span>`;
                    }
                    return str;
                }

                // 处理回单
                function eachhuidan(stepnum){
                    console.log();
                    var stepnum = stepnum - 1;
                    var str = '';
                    str += `<ul class="gj_con" style="margin-top:0.3rem;">`;
                    for(var m=0;m<stepnum;m++){
                        str += `<li onclick="window.location.href='./huidan_show.html?contantnum=contant` + (m+1) + `&huidanname=处理回单` + (m+1) + `'">
                            <span class="lileft">处理回单`+ (m+1) + `</span>
                            <span class="liright"><img src="../../images/arrowsr.svg" alt=""></span>
                            </li>`;
                    }
                    str += `</ul>`;
                    return str;
                }



                // 工单处理---单选框选中事件
                $('input:radio[name="deal"]').change(function () {
                    if ($("#topass").is(":checked")) {
                        $("#ender").hide();

                    }
                    if ($("#toback").is(":checked")) {
                        $("#ender").show();
												
                        // 获取审核处理人的名单
                        $.ajax({
                            type: "GET",
                            dataType: "json",
                            url: "http://112.74.169.99:21021/api/services/app/DevOpsService/GetUserInfoList",
                            beforeSend: function (xhr) {
                                xhr.setRequestHeader("Accept",
                                    "application/json, text/javascript, */*; q=0.01"
                                );
                                xhr.setRequestHeader("Authorization", accessToken);
                                xhr.setRequestHeader('.AspNetCore.Culture',
                                    'zh-Hans');
                            },
                            success: function (res) {
                                if(res.success){
                                    console.log(orderzxr);
                                    $("#selectclr").html(' ');
                                    $("#selectclr").append( eachclr(res.result,orderzxr) );
                                }
                                console.log(res);
                            },
                            error: function (err) {
                                console.log("请求失败");
                            }
                        });

                    }
                })

                function eachclr(lilength,orderzxr){
                    var str = ``;
                    for(var j=0;j < lilength.length;j++){
                        if( lilength[j].userName != orderzxr ){
                            str += `<option id="` + lilength[j].userID + `" userName="` + lilength[j].userName + `">` + lilength[j].userName + `</option>`;
                        }
                    }
                    return str;
                }
                
                
                
                // 提交
                $("#sub_btn").click(function(){
                    const subshunxu = async () => {
                        resresult.stepnum = stepnum;// 更新执行次数
                        var itemcon = {};
                        itemcon.dealtime = getDate();
						resresult.completetime =  getDate();//完成时间
                        if( $("#topass").is(":checked") ){
                            resresult.orderstate = 2;//工单状态:已完成
                            itemcon.pass = 'yes';
                        }
                        if( $("#toback").is(":checked") ){
                            resresult.orderstate = 0;//工单状态:待处理
                            itemcon.pass = 'no';
                            itemcon.nopassid = $("#selectclr").find("option:selected").attr("id")
                            itemcon.nopassname = $("#selectclr").find("option:selected").attr("userName")
                            itemcon.nopasswhy = $("#selectend").val();
                            resresult.executorname = $("#selectclr").find("option:selected").attr("userName");//下一个工单执行人
                            resresult.executorid = $("#selectclr").find("option:selected").attr("id");//下一个工单执行人id
                        }
                        
                        var itemname = "contant" + stepnum;
                        ordercontant[itemname] = itemcon;

                        ordercontant = JSON.stringify(ordercontant);
                        resresult.ordercontant = ordercontant;
                        resresult.executortime =  getDate();//执行时间
                        resresult.assignortime =  getDate();//指派时间
                        resresult.creattime = dealcreattime; //创建时间

                        console.log(resresult.ordercontant);
                        console.log(resresult);
                        resresult = JSON.stringify(resresult);

                        $.ajax({
                            url: "http://112.74.169.99:21021/api/services/app/DevOpsService/CreatAfterSaleOrderByUpdate",
                            data: resresult,
                            type: "post",
                            dataType: "json",
                            beforeSend: function (xhr) {
                                xhr.setRequestHeader("Content-Type", "application/json");
                                xhr.setRequestHeader(
                                    "Accept",
                                    "application/json, text/plain, */*"
                                );
                            },
                            success: function (res) {
                                console.log(res);
                                window.location.href = "../project_aftersale.html?projectid=" + projectid + "&projectname=" +projectNameCN;
                            },
                            error: function (err) {
                                console.log("请求失败");
                            }
                        });
                    }

                    subshunxu();


                });


                // 获取当前时间
                function getDate(){
                    var myDate = new Date();
                    //获取当前年
                    var year = myDate.getFullYear();
                    //获取当前月
                    var month = myDate.getMonth() + 1;
                    //获取当前日
                    var date = myDate.getDate();
                    var h = myDate.getHours(); //获取当前小时数(0-23)
                    var m = myDate.getMinutes(); //获取当前分钟数(0-59)
                    var s = myDate.getSeconds();
                    //获取当前时间
                    var now = year + '-' + conver(month) + "-" + conver(date) + " " + conver(h) + ':' + conver(m) + ":" + conver(s);
                    return now;
                }

                //日期时间处理
                function conver(s) {
                    return s < 10 ? '0' + s : s;
                }


            }
            getinfo();

        });
    </script>

</body>

</html>